package main.java;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class App {
	
	//Fichier de configuration
	private static final String CONF = "src/main/java/conf";

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		// Lecture du login, du pass et de la clef pour l'identification
		String MAIL = null;
		String PASS = null;
		String KEY = null;
		try {
			File conf = new File(CONF);
			InputStream ips = new FileInputStream(conf);
			InputStreamReader ipsr = new InputStreamReader(ips);
			BufferedReader br = new BufferedReader(ipsr);
			String ligne;
			while ((ligne = br.readLine()) != null) {
				if (ligne.contains("MAIL")) {
					MAIL = ligne.substring(5);
				} else if (ligne.contains("PASS")) {
					PASS = ligne.substring(5);
				} else if (ligne.contains("KEY")) {
					KEY = ligne.substring(4);
				}
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(MAIL!=null && PASS!=null && KEY!=null) {
			System.out.println("Lecture fichier de configuration : OK!");
			System.out.println("User : "+MAIL);
		} else {
			throw new Exception();
		}

		//Authentification EA
		Server eaServer = new Server(MAIL, PASS, "2131230799");
		try {
			eaServer.login();
			eaServer.loadAccountInfo();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
